    	$(function() {
    	    var address_id = GetQueryString('address_id');
    	    var userId = getcookie('userId');


    	    $.ajax({
    			type:'post',
    			url:WapSiteUrl+'/address/areaList',
    			//data:{paId:null},
    			dataType:'json',
    			success:function(result){
    				//checklogin(result.login);
    				var data = result.datas;
    				//alert(data);
    				var prov_html = '';
    				for(var i=0;i<data.length;i++){
    					prov_html+='<option value="'+data[i].areaId+'">'+data[i].areaName+'</option>';
    				}
    				$("select[name=prov]").append(prov_html);
    			}
    		});

    	    $("select[name=prov]").change(function() {
    	        var prov_id = $(this).val();
    	        $.ajax({
    	            type: 'post',
    	            url: WapSiteUrl+'/address/areaList',
    	            data: {
    	            	paId: prov_id
    	            },
    	            dataType: 'json',
    	            success: function(result) {
    	                var data = result.datas;
    	                var city_html = '<option value="">请选择...</option>';
    	                for (var i = 0; i < data.length; i++) {
    	                    city_html += '<option value="' + data[i].areaId + '">' + data[i].areaName + '</option>';
    	                }
    	                $("select[name=city]").html(city_html);
    	                $("select[name=region]").html('<option value="">请选择...</option>');
    	            }
    	        });
    	    });

    	    $("select[name=city]").change(function() {
    	        var city_id = $(this).val();
    	        $.ajax({
    	            type: 'post',
    	            url: WapSiteUrl+'/address/areaList',
    	            data: {
    	            	paId: city_id
    	            },
    	            dataType: 'json',
    	            success: function(result) {
    	                checklogin(result.login);
    	                var data = result.datas;
    	                var region_html = '<option value="">请选择...</option>';
    	                for (var i = 0; i < data.length; i++) {
    	                    region_html += '<option value="' + data[i].areaId + '">' + data[i].areaName + '</option>';
    	                }
    	                $("select[name=region]").html(region_html);
    	            }
    	        });
    	    });

    	    //$('#editaddress').click(function() {
    	    //    if ($('input[name=modifyaddr]').val() == '1') {
    	    //        $('input[name=modifyaddr]').val(2);
    	    //        $('input[name=areaId').val('');
    	    //        $('input[name=cityId').val('');
    	    //        $('input[name=areaInfo').val('');
    	    //        $('input[name=address').val('');
    	    //        $('#area').show();
    	    //    } else {
    	    //        $('input[name=modifyaddr]').val(1);
    	    //        $('#area').hide();
    	    //    }
    	    //});

            $.sValid.init({
                rules:{
                    true_name:"required",
                    mob_phone:"required",
                    areaId:"required",
                    address:"required"
                },
                messages:{
                    true_name:"姓名必填！",
                    mob_phone:"手机号必填！",
                    areaId:"地址必填！",
                    address:"街道必填！"
                },
                callback:function (eId,eMsg,eRules){
                    if(eId.length >0){
                        var errorHtml = "";
                        $.map(eMsg,function (idx,item){
                            errorHtml += "<p>"+idx+"</p>";
                        });
                        $(".error-tips").html(errorHtml).show();
                    }else{
                         $(".error-tips").html("").hide();
                    }
                }  
            });
    	    $('.add_address').click(function() {
                if($.sValid()){
        	        var true_name = $('input[name=true_name]').val();
        	        var mob_phone = $('input[name=mob_phone]').val();
        	        var tel_phone = $('input[name=tel_phone]').val();
        	        var address_id = $('input[name=addressId]').val();
					var is_default =$('input[name=is_default]').val();

        	        var op = $('input[name=modifyaddr]').val();
        	        if (op == '2') {
        	            var city_id = $('select[name=city]').val();
        	            var area_id = $('select[name=region]').val();
        	            var address = $('input[name=address]').val();

        	            var prov_index = $('select[name=prov]')[0].selectedIndex;
        	            var city_index = $('select[name=city]')[0].selectedIndex;
        	            var region_index = $('select[name=region]')[0].selectedIndex;
        	            var area_info = $('select[name=prov]')[0].options[prov_index].innerHTML + ' ' + $('select[name=city]')[0].options[city_index].innerHTML + ' ' + $('select[name=region]')[0].options[region_index].innerHTML;
						if(prov_index ==0 ||city_index ==0 || region_index ==0){
                           return false;
						}

        	        } else {
        	            var city_id = $('input[name=cityId]').val();
        	            var area_id = $('input[name=areaId]').val();
        	            var address = $('input[name=address]').val();
        	            var area_info = $('input[name=areaInfo]').val();
        	        }


        	        $.ajax({
        	            type: 'post',
        	            url: WapSiteUrl+"/address/editAddr",
        	            data: {
        	            	memberId: userId,
        	                trueName: true_name,
        	                mobPhone: mob_phone,
        	                telPhone: tel_phone,
        	                cityId: city_id,
        	                areaId: area_id,
        	                address: address,
        	                areaInfo: area_info,
        	                addressId: address_id,
							isDefault: is_default
        	            },
        	            dataType: 'json',
        	            success: function(result) {
        	                if (result) {
        	                    location.href =$('#direct_url').val();
        	                } else {
        	                    location.href = WapSiteUrl;
        	                }
        	            }
        	        });
                }
    	    });
    	});